package UIComponents.Messages
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;

	/**
	 * 消息条
	 * @author 邓坚
	 * 
	 */
	public class MessageItem extends Sprite
	{
		public var _picUse:Sprite;                  //用户头像
		public var _txtUseName:TextField;           //用户名显示框
		public var _txtMessageContent:TextField;    //消息内容显示框
		public var _txtData:TextField;              //消息日期显示框
		public var _txtTime:TextField;              //消息时间显示框
		public var _btnC:Sprite;                    //按扭容器
		
		public var _id:uint;                        //id
		public var message:UseMessage;
		public function MessageItem()
		{
			init();
		}
		
		public function init():void
		{
			_picUse        			= this.getChildByName("picUse") as Sprite;
			_txtUseName    			= this.getChildByName("txtUseName") as TextField;
			_txtMessageContent		= this.getChildByName("txtMessageContent") as TextField;
			_txtData 				= this.getChildByName("txtDate") as TextField;
			_txtTime				= this.getChildByName("txtTime") as TextField;
			_btnC		 			= this.getChildByName("btnC") as Sprite;
			
			_txtData.maxChars	=	20;

		}

		
		/**
		 * 设置一条消息到框内 
		 * @param useMessage
		 * 
		 *///显示型 0全部，1礼物，2求赠，3互动，付费   消息类型（3为消费，4为互动，5为求赠，1为礼物）
		public function setItem(useMessage:UseMessage):void
		{
			message	=	useMessage;
			_id = useMessage.ztId;
			setTxtUseName(useMessage.ztFriendName);
			setTxtMessageContent(useMessage.Content);
			setTxtDateTime(useMessage.ztMessageTime);
			setBtnContainer(useMessage.ztMessageType,useMessage.ztId);
			
			setPicUse(message.ztUsePicSp);
		}
		
		/**
		 * 设置按扭容器 
		 * @param type
		 * @param id
		 * 
		 */
		public function setBtnContainer(type:Number=-1,id:uint=0):void
		{
			while(_btnC.numChildren)_btnC.removeChildAt(0);
			if(type==-1)return;
			if(!message.ztStatus)return;
			
			
			switch(type)							//消息类型（3为消费，4为互动，5为求赠，1为礼物）
			{
				case 1:
					var bjs:BtnJiSo		=	new BtnJiSo();
					bjs._id 			= 	id;
					_btnC.addChild(bjs);
					break;
				case 5:
					var bs:BtnSend		=	new BtnSend();
					bs._id	 			= 	id;
					_btnC.addChild(bs);
					break;
				case 3:
				case 4:
					var bc:BtnConfirm	=	new BtnConfirm();
					bc._id 				= 	id;
					_btnC.addChild(bc);
					break;
			}
		}
		
		/**
		 * 设置用户头像 
		 * @param value
		 * 
		 */
		public function setPicUse(value:DisplayObject):void
		{
			while(_picUse.numChildren)_picUse.removeChildAt(0);//_picUse.numChildren-1);              //消空图像  
			if(value==null)return;
			
			this._picUse.addChild(value);
		}
		
		/**
		 * 设置用户的名字 
		 * @param value
		 * 
		 */
		public function setTxtUseName(value:String=""):void
		{
			_txtUseName.text = "玩家"+value;
			if(value=="")_txtUseName.text="";
		}
		
		/**
		 * 设置消息内容 
		 * @param value
		 * 
		 */
		public function setTxtMessageContent(value:String=""):void
		{
			if(null==value)return;
			_txtMessageContent.text = value;
		}
		
		/**
		 * 设置时间跟日期
		 * @param newDate
		 * 
		 */
		public function setTxtDateTime(newDate:Date=null):void
		{
			if(newDate==null){
				_txtData.text = "";
				_txtTime.text = "";
				return;
			}
			_txtData.text = /*newDate.fullYear+"-"+*/newDate.month+"-"+newDate.getDate();
			_txtTime.text = newDate.hours+":"+newDate.minutesUTC+":"+newDate.seconds;
			
		}
		
		/**
		 * 设置所有值为空 
		 * 
		 */
		public function setNull():void
		{
			this.setPicUse(null);
			this.setTxtMessageContent();
			this.setTxtUseName();
			this.setTxtDateTime();
			this.setBtnContainer();
		}
	}
}